package packets.c2spackets;

import network.MCConnection;
import exceptions.UnrecoverableException;
import packets.PacketHandler;
import world.WorldState;

/**
 * This is a non-MC packet. It is used to simulate a real client disconnection.
 * The connection assumed (asserted) to already been closed.
 * @author remco_lw
 *
 */
public class P0xFF0 extends PacketHandler {

	public P0xFF0(WorldState worldstate) {
		super(worldstate);
	}

	@Override
	public void handle(MCConnection conn) throws UnrecoverableException {
		getWorldState().connectionManager().removePlayer(conn);
		
		if(conn.getPlayer() != null) {
			getWorldState().entitymanager().removeEntity(conn.getPlayer());			
			getWorldState().playermanager().deregisterPlayer(conn.getPlayer());
			conn.setPlayer(null);
		}
	}

}
